﻿using System;
using System.IO;
using System.Linq;
using System.Web.Hosting;
using System.Reflection;

namespace Caramel.Web.Hosting
{
	public class AssemblyResourceFile : VirtualFile 
	{
		public AssemblyResourceFile(string assemblyFullName, string resourceName, string virtualPath)
			: base(virtualPath)
		{
			this.AssemblyFullName = assemblyFullName;
			this.ResourceName = resourceName;
		}

		protected string AssemblyFullName { get; private set; }

		protected string ResourceName { get; private set; }

		public override Stream Open()
		{
			return
				AppDomain.
					CurrentDomain.
					GetAssemblies().
					First(a => a.FullName == this.AssemblyFullName).
					GetManifestResourceStream(this.ResourceName);
		}
	}
}
